package com.lin.jfreeChart;

import org.jfree.data.general.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;

import java.awt.Font;
import org.jfree.chart.title.TextTitle;
import org.jfree.chart.title.LegendTitle;
import com.opensymphony.xwork2.ActionSupport;

public class PieChartAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JFreeChart chart;

	public JFreeChart getChart() {
		chart = ChartFactory.createPieChart("图书销量统计图", getDataSet(), true, false, false);

		chart.setTitle(new TextTitle("图书销量统计图", new Font("黑体", Font.ITALIC, 22)));

		LegendTitle legend = chart.getLegend(0);

		legend.setItemFont(new Font("宋体", Font.BOLD, 14));

		PiePlot plot = (PiePlot) chart.getPlot();

		plot.setLabelFont(new Font("隶书", Font.BOLD, 18));

		plot.setBackgroundAlpha(0.9f);

		plot.setForegroundAlpha(0.50f);
		return chart;
	}

	private DefaultPieDataset getDataSet() {
		DefaultPieDataset dataset = new DefaultPieDataset();
		dataset.setValue("疯狂Java讲义", 47000);
		dataset.setValue("轻量级Java EE企业实战", 38000);
		dataset.setValue("疯狂Ajax讲义", 31000);
		dataset.setValue("Struts 2权威指南", 29000);
		dataset.setValue("疯狂XML讲义", 25000);
		return dataset;
	}
}
